#ifndef REGISTERMODEL_H
#define REGISTERMODEL_H

#include <QAbstractTableModel>

#include "registerdef.h"

class RegisterModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    RegisterModel(QObject *parent=0);
    ~RegisterModel();

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    virtual QVariant headerData(int sections, Qt::Orientation orientation, int role) const;
    virtual int rowCount(const QModelIndex &parent=QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent=QModelIndex()) const;
    virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole);

    void setRegisterList(QList<RegisterDef> *regList);

    virtual QStringList mimeTypes() const;
    virtual QMimeData* mimeData(const QModelIndexList &indexes) const;

public slots:
    virtual void dataRefreshed(RegisterDef reg);

signals:
    void writeNeeded(int address, QString value);
    void readNeeded(int address);

protected:
    QList<RegisterDef> *m_regList;
};

class RegisterRefreshModel : public RegisterModel
{
    Q_OBJECT

public:
    RegisterRefreshModel(QObject *parent=0);
    ~RegisterRefreshModel();

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role);
    virtual int rowCount(const QModelIndex &parent=QModelIndex()) const;
    virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent=QModelIndex());

public slots:
    virtual void dataRefreshed(RegisterDef reg);
    void removeRegisters(QList<QModelIndex> selected);
    void updateRegisters();
    void start(int msecs);
    void pause();

private:
    QList<RegisterDef> m_graphedRegList;
    QTimer *timer;
};

#endif // REGISTERMODEL_H
